package com.yz.rabbitmq.confirm;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.yz.rabbitmq.ChannelsUtil;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * 描述：
 **/
public class ConfirmCon {

    public static void main(String[] args) throws IOException {
        Channel channel = ChannelsUtil.getChannel();
        channel.exchangeDeclare("confirm_fanout","fanout",true);
        channel.queueDeclare("confirm_queue",true,false,false,null);
        channel.queueBind("confirm_queue","confirm_fanout","ss");
        channel.basicConsume("confirm_queue", false, new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                try {

                    TimeUnit.SECONDS.sleep(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(new String(body));
            }
        });
    }
}
